package com.sailing.lianxi.net.tcp;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.Socket;
import java.net.UnknownHostException;

public class Client {

	public static void t1(){
		String serverIp = "127.0.0.1";
		int port = 2000;
		try {
			//创建客户端连接对象，当连接对象创建时，就会和服务端建立连接
			Socket socket = new Socket(serverIp,port);
			//设置连接超时时间
			socket.setSoTimeout(3000);
			//将socket输入流包装成bufferedReader
			BufferedReader br = new BufferedReader(new InputStreamReader(socket.getInputStream()));
			String line= br.readLine();
			System.out.println("客户端接收来自服务器端数据："+line);
			//关闭流
			br.close();
			//关闭socket
			socket.close();
		} catch (Exception e) {
			// TODO Auto-generated catch block
			System.out.println("client 连接失败");
			e.printStackTrace();
		} 
	}
	
	public static void main(String[] args) {
		t1();
	}
}
